package top.jacktgq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author weiming
 * @date 2022/9/2 10:38
 * @description
 */
@RestController
@Slf4j
public class CloseController {

    @Autowired
    ConfigurableApplicationContext applicationContext;

    @GetMapping("/close")
    public String close(){
        applicationContext.close();
        return "true";
    }

    static {
        Runtime runtime = Runtime.getRuntime();
        runtime.availableProcessors();
        Thread thread = new Thread(() -> {
            log.info("ShutdownHook");
        }, "ShutdownHook");
        runtime.addShutdownHook(thread);
        runtime.removeShutdownHook(thread);
    }
}
